package com.le.tester.javaThink.fifth.chapter24_ConcurrentProgramming;

/**
 * createTime：2021/8/23 14:51
 * description：Philosopher 拿起筷子，放下筷子，座位，左边，右边
 */
public class Philosopher implements Runnable {

    private final int seat;
    private final StickHolder left, right;

    public Philosopher(int seat, StickHolder left, StickHolder right) {
        this.seat = seat;
        this.left = left;
        this.right = right;
    }

    @Override
    public String toString() {
        return "Philosopher{" +
                "seat=" + seat +
                ", left=" + left +
                ", right=" + right +
                '}';
    }

    @Override
    public void run() {
        while (true) {
            right.pickUp();
            left.pickUp();
            System.out.println(this + " eating");
            right.putDown();
            left.putDown();
        }
    }
}
